<!-- Generated automatically from an XML file of the same name.
     Copyright: Stephen J. Sangwine and Nicolas Le Bihan, 2008-2011.
--><html><head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
   <title>slerp :: Functions (Quaternion Toolbox Function Reference)
</title><link rel="stylesheet" href="qtfmstyle.css" type="text/css"></head><body><h1>Quaternion Function Reference</h1><h2>slerp</h2>
<p>Spherical linear interpolation</p>
<h2>Syntax</h2><p><tt>y = slerp(q1, q2, t)</tt></p>
<h2>Description</h2>
<p>
<tt>slerp(q1, q2, t)</tt> interpolates between two quaternions
<tt>q1</tt> and <tt>q2</tt>,
using parameter <tt>t</tt> to determine how far along the 'arc'
between the two quaternions to position the result (0 &#8804; <tt>t</tt> &#8804; 1).
</p>
<p>
<tt>q1</tt> and <tt>q2</tt> must be of the same size.
Either the two quaternions, or <tt>t</tt>,
must be scalar, or <tt>t</tt> must have the same size as the
two quaternions.
</p>
<p>
The third parameter, <tt>t</tt>, gives the 'distance' along the 'arc' between the
quaternions, 0 representing <tt>q1</tt> and 1 representing <tt>q2</tt>.
If <tt>q1</tt> and <tt>q2</tt> are
unit pure quaternions, the interpolation is along a great circle of the
sphere between the points represented by <tt>q1</tt> and <tt>q2</tt>.
If <tt>q1</tt> and <tt>q2</tt> are unit
full quaternions, the interpolation is along the 'arc' on the 4-sphere:
this means the result is a quaternion which represents a rotation
intermediate between the two rotations represented by <tt>q1</tt> and
<tt>q2</tt>. If the
first two parameters are not unit quaternions, then there is also
interpolation in modulus.
</p>
<p>
<tt>q1</tt> and <tt>q2</tt> are not restricted to be real quaternions.
</p>
<p>
The slerp function can be simply understood in terms of the ratio of two
vectors (pure quaternions). The ratio is the quaternion that rotates one
vector into the other. Taking a fractional power of this rotation and
then multiplying it by the first vector obviously gives a vector which is
part way along the arc between the two quaternions. The ratio is computed
using the multiplicative inverse. If the two quaternions are full, then
their ratio again gives a quaternion which multiplies one to give the
other, but this time in 4-space, including, if the moduli are not unity,
the scale factor needed to scale one into the other.
</p>

<h2>Examples</h2>To interpolate between <tt>qi</tt> and <tt>qj</tt>,
we can supply a vector for <tt>t</tt>. The result shows that
when <tt>t</tt> is zero, the result is <tt>qi</tt>, and when
<tt>t</tt> is 1, the result is <tt>qj</tt>. At the mid-point of
the interpolation, we get <tt>qi</tt>/&#8730;2 + <tt>qj</tt>/&#8730;2, the
mid-point of the arc in 3-space:
<pre>
&gt;&gt; arc = slerp(qi, qj, [0:0.2:1])
 
arc = 1x6 quaternion array
 
&gt;&gt; show(arc)
 
arc.S = 0     0     0     0     0     0

arc.X = 1.0000    0.9511    0.8090    0.5878    0.3090    0.0000

arc.Y = 0    0.3090    0.5878    0.8090    0.9511    1.0000

arc.Z = 0     0     0     0     0     0
</pre>

<h2>References</h2><ol><li>Ken Shoemake,
'Animating rotation with quaternion curves',
<i>SIGGRAPH Computer Graphics</i>,
<b>19</b> (3), July 1985, 245-254, ACM, New York, USA.

DOI: <a href="http://dx.doi.org/10.1145/325165.325242">10.1145/325165.325242</a>.
</li></ol>
<h4>&copy; 2008-2011 Stephen J. Sangwine and Nicolas Le Bihan</h4><p><a href="license.html">License terms.</a></p></body></html>